package com.kfm.spring.controller;

import com.kfm.spring.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

//@Controller
//@ResponseBody
@RestController
public class ResponseController {

    @RequestMapping("/mv")
    public ModelAndView index(ModelAndView modelAndView) {
        // 创建模型视图对象
//        ModelAndView mv = new ModelAndView("mv");
//        ModelAndView modelAndView = new ModelAndView();
        // 存数据
        modelAndView.addObject("name", "kfm");
        // 设置逻辑视图名称
        modelAndView.setViewName("mv");
        return modelAndView;
    }

    @RequestMapping("/mv2")
    public ModelAndView index2(ModelAndView modelAndView) {
        // 创建模型视图对象
        modelAndView.setViewName("forward:/mv3");
        return modelAndView;
    }

    @RequestMapping("/mv3")
    public String index3() {
        return "forward:/WEB-INF/pages/mv.jsp";
    }

    @RequestMapping("/mv4")
    @ResponseBody
    public User index4() {
        User user = new User();
        user.setId(4);
        user.setUsername("开发喵");
        user.setPassword("123456");
        user.setAge(18);
        return user;
    }




    @RequestMapping("/mv5")
    public String index5() {
        throw new RuntimeException("出错了, 模拟异常");
    }


}
